package com.smartfast4j.filesystem.controller;

import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 使用@WebServlet配置UploadServlet的访问路径
 */
@WebServlet(name="pluploadFileInfoServlet",urlPatterns="/pluploadFileInfoServlet")
public class PluploadFileInfoServlet extends HttpServlet {

    private static Logger logger = Logger.getLogger(PluploadFileInfoServlet.class);

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String msg = "您上传了：<br/>";
        String[] fileUrls = request.getParameterValues("fileUrl");
        String[] fileNames = request.getParameterValues("fileName");
        for (int i = 0; i < fileUrls.length; i++) {
            msg += "文件路径：" + fileUrls[i] + " 文件名称：" + fileNames[i] + "<br/>";
            logger.debug(fileUrls[i] + " " + fileNames[i]);
        }
        String name = request.getParameter("name");
        msg += "用户名：" + name + "<br/>";
        String pwd = request.getParameter("pwd");
        msg += "密码：" + pwd + "<br/>";
        request.setAttribute("msg", msg);
        logger.debug("msg="+msg);
        request.getRequestDispatcher("/success.jsp").forward(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doGet(request, response);
    }
}